<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义遍历数据</title>
</head>
<body>
    <script>
        //需求   for...of 对 team 进行遍历, 要求每次返回 members 中的成员
        const team = {
            name: '终极一班',
            members: [
                'xiaoming',
                'xiaoning',
                'xiaotian',
                'knight'
            ],
            
            //添加 Symbol.iterator 方法
            [Symbol.iterator](){
                //下标
                let index = 0;
                return {
                    next: () => {
                        //判断下标
                        if(index < this.members.length){
                            return {
                                value: this.members[index++], 
                                done: false
                            }
                        }else{
                            return {
                                value: undefined,
                                done: true
                            }
                        }
                    }
                }
            }
        }

        for(let v of team){
            console.log(v);
        }

        for(let v of team){
            console.log(v);
        }

    </script>
</body>

</html>